package com.qf.zyh.entity;

public class Pages {
    //当前页码
    private Integer pageIndex;
    //每页行数
    private Integer pageSize;
    //总页数
    private Integer totalPage;
    //数据总行数
    private Integer totalCount;
    //起始行数
    private Integer statrRow;

    public Pages(Integer pageIndex, Integer pageSize, Integer totalCount) {
        //设置每页输出五个数据
        if (pageSize<=0) {
            //外部设置的行数小于0则默认为5行每页
            this.pageSize=5;
        }else {
            //外部设置正常行数则按外部行数输出
            this.pageSize=pageSize;
        }
        //通过数据总行数来获取页数
        this.totalCount = totalCount;
        //用总行数除以每页行数得到总页数。进行向上取整，有小数则+1，有一行数据也+1页。
        this.totalPage= (int)Math.ceil(totalCount/(pageSize+0.0));
        //当前页数小于1的时候，设置为第一页，
        if (pageIndex<1){
            this.pageIndex=1;
            //当前页数大于最后一页时，设置为最后一页。
        }else if (pageIndex>this.totalPage){
            this.pageIndex=this.totalPage;
        }else {
            //正常页数
            this.pageIndex = pageIndex;
        }
        //设置起始页，来判断每页第一个数据在数据库的哪个位置，由当前页数-1乘以每页显示的行数
        this.statrRow=(this.pageIndex-1)*this.pageSize;

    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getStatrRow() {
        return statrRow;
    }

    public void setStatrRow(Integer statrRow) {
        this.statrRow = statrRow;
    }
}
